import java.util.ArrayList;
import java.util.Arrays;

public class Test {
    //合并两个有序数组
    public static void merge(int[] nums1, int m, int[] nums2, int n) {
        int p1 = 0;
        int p2 = 0;
        while(p1 < n + m && p2 < n){
            if(nums1[p1] <= nums2[p2]){
                p1++;
            }
            else{
                for (int i = p2 + m - 1; i >= p1 ; i--) {
                    nums1[i + 1] = nums1[i];
                }
                nums1[p1] = nums2[p2];
                p2++;
                p1++;
            }
        }
        while (p2 < n){
            nums1[m + p2] = nums2[p2];
            p2++;
        }
    }
    public static void main(String[] args) {
        int[] nums1 = {4,5,6,0,0,0};
        int[] nums2 = {1,2,3};
        int m = 3;
        int n = 3;
        merge(nums1,m,nums2,n);
        System.out.println(Arrays.toString(nums1));
    }
}
